home *** CD-ROM | disk | FTP | other *** search
/ C# & Game Programming - A…er's Guide (2nd Edition) / Buono 2nd Ed.iso / Chapter5 / 5.57 / 5.57.cs next >
Text File  |  2004-09-07  |  1KB  |  42 lines

  1. /* The keyword lock. */
  2. using System;
  3. using System.Threading;
  4.  
  5. namespace Chapter5 {
  6.     class MyName { 
  7.         private string name;
  8.         protected MyName(string fn) {this.name = fn;}
  9.         protected string TestName(string fn) { 
  10.             if (fn == "Sal") { 
  11.                 throw new Exception("Welcome Home!");
  12.             }
  13.  
  14.             lock (this) {
  15.                 if (fn != null) { 
  16.                     return ("nice to meet you" + this.name);
  17.                 }
  18.             }
  19.             return "The End";
  20.         }
  21.  
  22.         protected void YourName() { 
  23.             Console.WriteLine("What is your name?");
  24.             string input = Console.ReadLine();
  25.             TestName(input);
  26.         }
  27.  
  28.         static protected Thread[] test = new Thread[2];
  29.  
  30.         public static void Main() { 
  31.             MyName FirstName = new MyName("Salvatore");
  32.             MyName LastName = new MyName("Buono");
  33.             Thread first = new Thread(new ThreadStart(FirstName.YourName));
  34.             test[0] = first;
  35.             test[0].Start();
  36.  
  37.             Thread last = new Thread(new ThreadStart(LastName.YourName));
  38.             test[1] = last;
  39.             test[1].Start();
  40.         }
  41.     }
  42. }